<template>  <div class="stat-card theme-blue user-card">
    <div class="user-greeting">
      <div class="user-image">
        <el-avatar :src="url" shape="circle" size="70" class="user-avatar"></el-avatar>
        <div class="avatar-ring"></div>
      </div>
      <div class="greeting">
        <span class="user-name">{{ `${getState}，${userName}` }}</span>
        <div class="user-subtitle">继续您的学习之旅</div>
      </div>
    </div>
    <div class="divider"></div>    
    <div class="btn-container">
    
      <!-- 最重要：学习功能 -->
      <el-button type="success" @click="toLearning" class="action-btn primary-important-btn">
        <i class="el-icon-reading"></i>
        开始学习
      </el-button>
      <!-- 重要：复习功能 -->
      <el-button type="primary" @click="toReview" class="action-btn secondary-important-btn">
        <i class="el-icon-refresh"></i>
        开始复习
      </el-button>
      <!-- 中等重要：今日单词 -->
      <el-button type="warning" @click="toToday" class="action-btn medium-important-btn">
        <i class="el-icon-date"></i>
        今日单词
      </el-button>
      <!-- 一般重要：辅助功能 -->
      <el-button type="info" @click="toChat" class="action-btn low-important-btn">
        <i class="el-icon-chat-dot-round"></i>
        专业问答讨论
      </el-button>
      <el-button type="info" @click="toEnglishChat" class="action-btn low-important-btn">
        <i class="el-icon-message"></i>
        情景对话练习
      </el-button>
      <el-button type="info" @click="toGeneratedStories" class="action-btn low-important-btn">
        <i class="el-icon-collection"></i>
        已生成故事
      </el-button>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request.js";

export default {
  name: "User",
  props: {
    url: String,
    userName: String,
  },
  data() {
    return {};
  },

  created: function () {},
  computed: {
    getState() {
      // 获取当前时间
      let timeNow = new Date();
      // 获取当前小时
      let hours = timeNow.getHours();
      // 设置默认文字
      let state = ``;
      // 判断当前时间段
      if (hours >= 0 && hours <= 10) {
        state = `早上好`;
      } else if (hours > 10 && hours <= 14) {
        state = `中午好`;
      } else if (hours > 14 && hours <= 18) {
        state = `下午好`;
      } else if (hours > 18 && hours <= 24) {
        state = `晚上好`;
      }
      return state;
    },
  },
  methods: {
    toGeneratedStories() {
    // 进入已生成故事界面
      this.$router.push("/generated-stories");
    },
    toLearning() {
      // 设置学习的模式，[learn];
      this.$store.commit("setLearningMode", "learn");
      // 先检查学习服务是否降级
      request.get("/memory/checkLearningServiceStatus")
        .then((res) => {
          if (res.data == true) {
            // 服务未降级，进入学习界面
            this.$router.push("/learn1");
          } else {
            // 服务已降级，显示错误信息
            this.$message.error(res.msg || "学习功能暂不可用，请稍后再试");
          }
        })
        .catch((error) => {
          // 请求失败，显示提示
          this.$message.error("服务异常，请稍后再试");
        });
    },
    toReview() {
      // 设置学习的模式，[review];
      this.$store.commit("setLearningMode", "review");
      // 先检查复习服务是否降级
      request.get("/memory/checkReviewServiceStatus")
        .then((res) => {
          if (res.data == true) {
            // 服务未降级，进入复习界面
            this.$router.push("/review1");
          } else {
            // 服务已降级，显示错误信息
            this.$message.error(res.msg || "复习功能暂不可用，请稍后再试");
          }
        })
        .catch((error) => {
          // 请求失败，显示提示
          this.$message.error("服务异常，请稍后再试");
        });
    },
    toToday() {
      // 设置浏览今日单词的模式，[today];
      this.$store.commit("setLearningMode", "today");
      // 先检查服务是否可用
      let userJson = localStorage.getItem("user");
      let user = JSON.parse(userJson);
      request.get("/memory/todayLearnedWords", {
        params: { userID: user.userID }
      }).then((res) => {
        if (res.code === "0") {
          // 服务正常，进入今日单词界面
          this.$router.push("/fast-story");
        } else {
          // 服务降级，显示提示
          this.$message.error(res.msg || "该服务暂不可用，请稍后再试");
        }
      }).catch((error) => {
        // 请求失败，显示提示
        this.$message.error("服务异常，请稍后再试");
      });
    },
    toChat() {
      // 进入聊天界面
      this.$router.push("/chat");
    },
    toEnglishChat() {
      // 进入英语聊天界面
      this.$router.push("/english-chat");
    },
  },
};
</script>

<style scoped>
.stat-card {
  margin: 0;
  height: 100%;
  min-height: 279px;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.user-greeting {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.user-image {
  position: relative;
  margin-right: 15px;
}

.avatar-ring {
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.7;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.greeting {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  margin: 15px 0;
}

.btn-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 0 8px;
  align-items: stretch;
}

.action-btn {
  width: 100% !important;
  height: 42px;
  border-radius: 10px;
  font-family: PingFang, sans-serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 1px;
  transition: all 0.3s ease;
  border: none !important;
  position: relative;
  overflow: hidden;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 0 !important;
  padding: 0 16px !important;
  text-align: center !important;
}

.action-btn i {
  margin-right: 8px;
  font-size: 16px;
}

.action-btn span {
  flex-shrink: 0;
}

.action-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* 最重要：开始学习 - 鲜艳的绿色渐变 */
.primary-important-btn {
  background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
  color: white;
  font-weight: 700;
}

.primary-important-btn:hover {
  background: linear-gradient(135deg, #00c4ff 0%, #3570cd 100%);
  box-shadow: 0 6px 25px rgba(58, 123, 213, 0.4);
}

/* 重要：开始复习 - 橙色渐变 */
.secondary-important-btn {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
  color: white;
  font-weight: 600;
}

.secondary-important-btn:hover {
  background: linear-gradient(135deg, #ff8a8e 0%, #fdbfdf 100%);
  box-shadow: 0 6px 25px rgba(255, 154, 158, 0.4);
}

/* 中等重要：今日单词 - 紫色渐变 */
.medium-important-btn {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  color: #333;
  font-weight: 600;
}

.medium-important-btn:hover {
  background: linear-gradient(135deg, #98ddda 0%, #edc6d3 100%);
  box-shadow: 0 6px 25px rgba(168, 237, 234, 0.4);
}

/* 一般重要：辅助功能 - 淡雅渐变 */
.low-important-btn {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  color: #666;
  font-weight: 500;
  font-size: 13px;
}

.low-important-btn:hover {
  background: linear-gradient(135deg, #efdcc2 0%, #ecb69f 100%);
  box-shadow: 0 6px 20px rgba(252, 182, 159, 0.3);
  color: #555;
}

@media (max-width: 707px) {
  .stat-card {
    margin: 0;
    min-height: 231px;
  }
  
  .action-btn {
    height: 38px;
    font-size: 13px;
  }
  
  .btn-container {
    gap: 8px;
    padding: 0 4px;
  }
  
  .action-btn i {
    font-size: 14px;
  }
}
</style>